package com.spbdx.system.service.workflow;

import com.spbdx.system.domain.EventOrder;
import com.spbdx.system.service.workflow.support.MachineStatusEvent;
import org.springframework.messaging.Message;
import org.springframework.statemachine.annotation.OnTransition;
import org.springframework.statemachine.annotation.WithStateMachine;
import org.springframework.stereotype.Component;

/**
 *
 * 维保单监听类
 * @author chenwei
 * @version 1.0
 * @date 2024/8/6 16:47
 */
@Component
@WithStateMachine(name = "machineState")
public class MachineStateListener {

    /**
     * 新单转为已接单处理逻辑
     *
     * @param message
     * @return
     */
    @OnTransition(source = "NEW", target = "ACCEPTED")
    public boolean acceptedTransition(Message<MachineStatusEvent> message) {
        EventOrder eventOrder = (EventOrder) message.getHeaders().get("eventOrder");
        System.out.println("新单转为已接单处理逻辑：" + message.getHeaders().toString());
        return true;
    }

    /**
     * 已接单状态转为已签到处理逻辑
     *
     * @param message
     * @return
     */
    @OnTransition(source = "ACCEPTED", target = "CHECKED_IN")
    public boolean checkedInTransition(Message<MachineStatusEvent> message) {
        EventOrder eventOrder = (EventOrder) message.getHeaders().get("eventOrder");
        System.out.println("已接单状态转为已签到处理逻辑：" + message.getHeaders().toString());
        return true;
    }

    /**
     * 已签到处理逻辑转为已完成维保处理逻辑
     *
     * @param message
     * @return
     */
    @OnTransition(source = "CHECKED_IN", target = "MAINTENANCE_FINISHED")
    public boolean maintenanceFinishedTransition(Message<MachineStatusEvent> message) {
        EventOrder eventOrder = (EventOrder) message.getHeaders().get("eventOrder");
        System.out.println("已签到处理逻辑转为已完成维保处理逻辑：" + message.getHeaders().toString());
        return true;
    }

    /**
     * 已完成维保处理逻辑转为已完成处理逻辑
     *
     * @param message
     * @return
     */
    @OnTransition(source = "MAINTENANCE_FINISHED", target = "FINISHED")
    public boolean finishedTransition(Message<MachineStatusEvent> message) {
        EventOrder eventOrder = (EventOrder) message.getHeaders().get("eventOrder");
        System.out.println("已完成维保处理逻辑转为已完成处理逻辑：" + message.getHeaders().toString());
        return true;
    }
}